package hshsm.managers;

import hsh.drivers.DeviceDriver;
import hsh.drivers.WasherDriver;
import hsh.exceptions.DeviceDriverNotFoundException;
import hshs.process.Process;

import java.util.ArrayList;
import java.util.Hashtable;
import java.util.List;
import java.util.PriorityQueue;

public class DeviceManager {

	private List<DeviceDriver> drivers;
	private Hashtable<DeviceDriver,PriorityQueue<Process>> deviceQueues;
	
	public DeviceManager() {
		deviceQueues = new Hashtable<DeviceDriver, PriorityQueue<Process>>();
		
		this.drivers = new ArrayList<DeviceDriver>();
		this.drivers.add(new WasherDriver());
		
		
		for(DeviceDriver drive: this.drivers){
			deviceQueues.put(drive, new PriorityQueue<Process>());
		}
	}
	
	public void installDriver(DeviceDriver driver){
		this.drivers.add(driver);
		this.deviceQueues.put(driver, new PriorityQueue<Process>());
	}
	
	public DeviceDriver searchDeviceDriver(String nameDevice) throws DeviceDriverNotFoundException{
		for(DeviceDriver driver : this.drivers){
			if(driver.getNameDevice().equals(nameDevice)){
				return driver;
			}
		}
		
		throw new DeviceDriverNotFoundException();
	}
	
}
